<?php
class ClassifyController extends CommonController{
	
	public $_model;
	public function __init(){
		$this->_model = K('Classify');
	}
	public function index(){
		
		$data = $this->_model->get_all_cfy(null,true);
		$this->assign('page',$data['page']);
		unset($data['page']);
		
		$this->assign('data',$data);
		$this->display();
	}
	
	//添加顶级分类
	public function addcfy(){
		if(IS_POST){
			$this->_model->add_cfy();
			$this->success('添加成功',U('index'));
		}
		$this->display();
	}
	
	//添加子集分类
	public function addsoncfy(){
		if(IS_POST){
			if(!$this->_model->add_cfy()){				
			$this->error($this->_model->error);
			}
			$this->success('添加成功',U('index'));
		}	
		$data = $this->_model->get_one_cfy(array('cid'=>Q('get.cid',0,'intval')),'cname');
		//分配cname变量
		$this->assign('cname',$data['cname']);
			
		$this->display();
	}
	//删除分类
	public function delete_cfy(){
		if($this->_model->del_cfy(Q('get.cid',0,'intval'))){
			$this->success('删除成功');
		}
		$this->error($this->_model->error);
	}
	
	
	//修改顶级分类
	public function editcfy(){
				
		if(IS_POST){
			if($this->_model->update_cfy(array('cid'=>Q('post.cid',0,'intval')))){
				$this->success('修改成功',U('index'));
			}else{
				$this->error($this->_model->error);
			}
			
		}		
		$cid = Q('get.cid',0,'intval');
		
		//获取旧数据		
		$olddata = $this->_model->get_one_cfy(array('cid'=>$cid));
		$this->assign('olddata',$olddata);
			
		$this->display();
	}
	
	
	
	
	
	
}//end
